import 'package:date_format/date_format.dart';
import 'package:quiver/strings.dart';

class ResPartner {
  String? id;
  String? customerNature; //客户性质
  String? name; //客户名称
  String? zip; //邮编
  String? area;
  String? countryId;
  String? countryName;
  String? city;
  String? contactAddress; //客户地址
  String? website; //公司网站地址
  String? customerLevel;
  String? customerState;
  String? customerType;
  String? customerSource;
  String? industryId; //所属行业
  String? industryName;
  String? creditRating;
  String? userId;
  String? userName; //用户名
  String? mainBusiness; //公司营业范围
  String? companyBackground;
  String? primaryContact; //公司法人姓名
  String? email; //电子邮件
  String? bank; //开户银行
  String? bankAccount; //银行账号
  String? vat; //税号
  String? phone; //企业电话
  String? comment;
  String? businessType; //企业类型
  String? ref; //供应商编码
  String? supplierAbbreviation; //供应商简称
  String? usedName; //供应商曾用名称
  String? person; //企业性质
  String? faxes; //传真
  String? factoryAddress; //生产工厂地址
  String? mobile; //法人联系方式
  String? investor; //公司投资人姓名
  String? investRatio; //各自投资比例
  String? regTime; //公司成立时间
  num? registerMoney; //注册资金(万元)
  num? fixedAssets; //固定资产(万元)
  String? processScale; //生产规模
  String? industrySort; //行业排序
  String? credibilityLetter; //银行资信证明
  String? areaName; //供货区域
  String? qq; //QQ
  String? productBrand; //产品品牌
  String? performanceProfile; //业绩简介
  String? enterpriseProfile; //企业简介
  String? userNameSupplier;
  String? officeAddress; //公司办公地址
  String? postalAddress; //信函通讯地址
  String? buyerId; //评价管理人

  ResPartner({
    this.id,
    this.customerNature,
    this.name,
    this.zip,
    this.area,
    this.countryId,
    this.countryName,
    this.city,
    this.contactAddress,
    this.website,
    this.customerLevel,
    this.customerState,
    this.customerType,
    this.customerSource,
    this.industryId,
    this.industryName,
    this.creditRating,
    this.userId,
    this.userName,
    this.mainBusiness,
    this.companyBackground,
    this.primaryContact,
    this.email,
    this.bank,
    this.bankAccount,
    this.vat,
    this.phone,
    this.comment,
    this.businessType,
    this.ref,
    this.supplierAbbreviation,
    this.usedName,
    this.person,
    this.faxes,
    this.factoryAddress,
    this.mobile,
    this.investor,
    this.investRatio,
    this.regTime,
    this.registerMoney,
    this.fixedAssets,
    this.processScale,
    this.industrySort,
    this.credibilityLetter,
    this.areaName,
    this.qq,
    this.productBrand,
    this.performanceProfile,
    this.enterpriseProfile,
    this.userNameSupplier,
    this.officeAddress,
    this.postalAddress,
    this.buyerId,
  });

  ResPartner copyWith({
    String? id,
    String? customerNature,
    String? name,
    String? zip,
    String? countryId,
    String? city,
    String? contactAddress,
    String? website,
    String? customerLevel,
    String? customerState,
    String? customerType,
    String? customerSource,
    String? mainBusiness,
  }) {
    return new ResPartner(
      id: id ?? this.id,
      customerNature: customerNature ?? this.customerNature,
      name: name ?? this.name,
      zip: zip ?? this.zip,
      countryId: countryId ?? this.countryId,
      city: city ?? this.city,
      contactAddress: contactAddress ?? this.contactAddress,
      website: website ?? this.website,
      customerLevel: customerLevel ?? this.customerLevel,
      customerState: customerState ?? this.customerState,
      customerType: customerType ?? this.customerType,
      customerSource: customerSource ?? this.customerSource,
      mainBusiness: mainBusiness ?? this.mainBusiness,
    );
  }

  @override
  String toString() {
    return '''ResPartner{
      id: $id,
      customerNature: $customerNature,
      name: $name,
      zip: $zip,
      area: $area,
      countryId: $countryId,
      countryName: $countryName,
      city: $city,
      contactAddress: $contactAddress,
      website: $website,
      customerLevel: $customerLevel,
      customerState: $customerState,
      customerType: $customerType,
      customerSource: $customerSource,
      industryId: $industryId,
      industryName: $industryName,
      creditRating: $creditRating,
      userId: $userId,
      userName: $userName,
      mainBusiness: $mainBusiness,
      companyBackground: $companyBackground,
      primaryContact: $primaryContact,
      email: $email,
      bank: $bank,
      bankAccount: $bankAccount,
      vat: $vat,
      phone: $phone,
      comment: $comment,
    }''';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      (other is ResPartner &&
          runtimeType == other.runtimeType &&
          id == other.id &&
          customerNature == other.customerNature &&
          name == other.name &&
          zip == other.zip &&
          countryId == other.countryId &&
          city == other.city &&
          contactAddress == other.contactAddress &&
          website == other.website &&
          customerLevel == other.customerLevel &&
          customerState == other.customerState &&
          customerType == other.customerType &&
          customerSource == other.customerSource &&
          mainBusiness == other.mainBusiness);

  factory ResPartner.fromMap(Map<String, dynamic> map) {
    return new ResPartner(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      customerNature: map['customer_nature'] != false
          ? map['customer_nature'].toString() as String?
          : "",
      name: map['name'] != false ? map['name'].toString() as String? : "",
      zip: map['zip'] != false ? map['zip'].toString() as String? : "",
      area: map['area'] != false ? map['area'].toString() as String? : "",
      countryId: map['country_id'] != false
          ? map['country_id'][0].toString() as String?
          : "",
      countryName: map['country_id'] != false
          ? map['country_id'][1].toString() as String?
          : "",
      city: map['city'] != false ? map['city'].toString() as String? : "",
      contactAddress: map['customer_address'] != false
          ? map['customer_address'].toString() as String?
          : "",
      website:
          map['website'] != false ? map['website'].toString() as String? : "",
      customerLevel: map['customer_level'] != false
          ? map['customer_level'].toString() as String?
          : "",
      customerState: map['customer_state'] != false
          ? map['customer_state'].toString() as String?
          : "",
      customerType: map['customer_type'] != false
          ? map['customer_type'].toString() as String?
          : "",
      customerSource: map['customer_source'] != false
          ? map['customer_source'].toString() as String?
          : "",
      industryId: map['industry_id'] != false
          ? map['industry_id'][0].toString() as String?
          : "",
      industryName: map['industry_id'] != false
          ? map['industry_id'][1].toString() as String?
          : "",
      creditRating: map['credit_rating'] != false
          ? map['credit_rating'].toString() as String?
          : "",
      userId: map['user_id'] != false
          ? map['user_id'][0].toString() as String?
          : "",
      userName: map['user_id'] != false
          ? map['user_id'][1].toString() as String?
          : "",
      userNameSupplier: map['user_name'] != false
          ? map['user_name'].toString() as String?
          : "",
      mainBusiness: map['main_business'] != false
          ? map['main_business'].toString() as String?
          : "",
      companyBackground: map['company_background'] != false
          ? map['company_background'].toString() as String?
          : "",
      primaryContact: map['primary_contact'] != false
          ? map['primary_contact'].toString() as String?
          : "",
      email: map['email'] != false ? map['email'].toString() as String? : "",
      bank: map['bank'] != false ? map['bank'].toString() as String? : "",
      bankAccount: map['bank_account'] != false
          ? map['bank_account'].toString() as String?
          : "",
      vat: map['vat'] != false ? map['vat'].toString() as String? : "",
      phone: map['phone'] != false ? map['phone'].toString() as String? : "",
      comment:
          map['comment'] != false ? map['comment'].toString() as String? : "",
      businessType: map['business_type'] != false
          ? map['business_type'].toString() as String?
          : "",
      ref: map['ref'] != false ? map['ref'].toString() as String? : "",
      supplierAbbreviation: map['supplier_abbreviation'] != false
          ? map['supplier_abbreviation'].toString() as String?
          : "",
      usedName: map['used_name'] != false
          ? map['used_name'].toString() as String?
          : "",
      person: map['person'] != false ? map['person'].toString() as String? : "",
      faxes: map['faxes'] != false ? map['faxes'].toString() as String? : "",
      factoryAddress: map['factory_address'] != false
          ? map['factory_address'].toString() as String?
          : "",
      mobile: map['mobile'] != false ? map['mobile'].toString() as String? : "",
      investor:
          map['investor'] != false ? map['investor'].toString() as String? : "",
      investRatio: map['invest_ratio'] != false
          ? map['invest_ratio'].toString() as String?
          : "",
      regTime:
          map['reg_time'] != false ? map['reg_time'].toString() as String? : "",
      registerMoney:
          map['register_money'] != false ? int.parse(map['register_money']) : 0,
      fixedAssets:
          map['fixed_assets'] != false ? int.parse(map['fixed_assets']) : 0,
      processScale: map['process_scale'] != false
          ? map['process_scale'].toString() as String?
          : "",
      industrySort: map['industry_sort'] != false
          ? map['industry_sort'].toString() as String?
          : "",
      credibilityLetter: map['credibility_letter'] != false
          ? map['credibility_letter'].toString() as String?
          : "",
      areaName: map['area_name'] != false
          ? map['area_name'].toString() as String?
          : "",
      qq: map['QQ'] != false ? map['QQ'].toString() as String? : "",
      productBrand: map['product_brand'] != false
          ? map['product_brand'].toString() as String?
          : "",
      performanceProfile: map['performance_profile'] != false
          ? map['performance_profile'].toString() as String?
          : "",
      enterpriseProfile: map['enterprise_profile'] != false
          ? map['enterprise_profile'].toString() as String?
          : "",
      officeAddress: map['office_address'] != false
          ? map['office_address'].toString() as String?
          : "",
      postalAddress: map['postal_address'] != false
          ? map['postal_address'].toString() as String?
          : "",
      buyerId: map['buyer_id'] != false
          ? map['buyer_id'][0].toString() as String?
          : "",
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'customerNature': this.customerNature,
      'name': this.name,
      'zip': this.zip,
      'countryId': this.countryId,
      'city': this.city,
      'contactAddress': this.contactAddress,
      'website': this.website,
      'customerLevel': this.customerLevel,
      'customerState': this.customerState,
      'customerType': this.customerType,
      'customerSource': this.customerSource,
      'mainBusiness': this.mainBusiness,
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    List list = [
      if (this.customerNature != null && this.customerNature != '')
        ['customer_nature', '=', this.customerNature],
      if (this.name != null && this.name != '')
        ['name', 'like', '%${this.name}%'],
      ['client_type', '=', '0']
    ];
    // ignore: unnecessary_cast
    return list;
  }

  List toDomainList1() {
    List list = [
      if (this.buyerId != null && this.buyerId != '')
        ['buyer_id', '=', int.parse(this.buyerId!)],
      if (this.name != null && this.name != '')
        ['name', 'like', '%${this.name}%'],
      ['client_type', '=', '1']
    ];
    return list;
  }

  Map<String, dynamic> toOdooMapSupplier() {
    // ignore: unnecessary_cast
    return {
      'id': id != null ? int.parse(this.id!) : null,
      'business_type': this.businessType,
      'ref': this.ref,
      'user_name': this.userNameSupplier,
      'name': this.name,
      'supplier_abbreviation': this.supplierAbbreviation,
      'used_name': this.usedName,
      'person': this.person,
      'zip': this.zip,
      'email': this.email,
      'phone': this.phone,
      'faxes': this.faxes,
      'office_address': this.officeAddress,
      'website': this.website,
      'factory_address': this.factoryAddress,
      'bank': this.bank,
      'bank_account': this.bankAccount,
      'primary_contact': this.primaryContact,
      'mobile': this.mobile,
      'investor': this.investor,
      'invest_ratio': this.investRatio,
      'reg_time': isBlank(this.regTime) ? null : this.regTime,
      'vat': this.vat,
      'register_money': this.registerMoney,
      'fixed_assets': this.fixedAssets,
      'process_scale': this.processScale,
      'industry_id': this.industryId,
      'industry_sort': this.industrySort,
      'credibility_letter': this.credibilityLetter,
      'area_name': this.areaName,
      'area': this.area,
      'QQ': this.qq,
      'postal_address': this.postalAddress,
      'main_business': this.mainBusiness,
      'product_brand': this.productBrand,
      'performance_profile': this.performanceProfile,
      'enterprise_profile': this.enterpriseProfile,
      'buyer_id': this.buyerId,
      'client_type': '1',
    } as Map<String, dynamic>;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': id != null ? int.parse(this.id!) : null,
      'customer_nature': this.customerNature,
      'name': this.name,
      'customer_level': this.customerLevel,
      'customer_type': this.customerType,
      'customer_state': this.customerState,
      'customer_source': this.customerSource,
      'industry_id': this.industryId != null ? int.parse(this.industryId!) : null,
      'credit_rating': this.creditRating,
      'main_business': this.mainBusiness,
      'company_background': this.companyBackground,
      'primary_contact': this.primaryContact,
      'email': this.email,
      'zip': this.zip,
      'area': this.area,
      'country_id': countryId != null ? int.parse(this.countryId!) : null,
      'city': this.city,
      'customer_address': this.contactAddress,
      'website': this.website,
      'user_id': userId != null && userId != "" ? int.parse(this.userId!) : null,
      'bank': this.bank,
      'bank_account': this.bankAccount,
      'vat': this.vat,
      'phone': this.phone,
      'comment': this.comment,
      'client_type': '0',
    } as Map<String, dynamic>;
  }

//</editor-fold>

}
